package com.example.behaviordemo.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.behaviordemo.R
import com.example.behaviordemo.adapter.ArticleAdapter
import com.example.behaviordemo.model.Article

/**
 * author : king_nina
 * e-mail : 13450414852@163.com
 * date   : 2021/12/2
 * desc   :
 */
class ArticleFragment : Fragment() {

    private lateinit var rootView: View
    private lateinit var recyclerView: RecyclerView
    private lateinit var articleAdapter: ArticleAdapter

    companion object {
        fun newInstance(): ArticleFragment {
            val fragment = ArticleFragment()
            return fragment
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        rootView = inflater.inflate(R.layout.fragment_article, container, false)
        initView()
        return rootView
    }

    private fun initView() {
        recyclerView = rootView.findViewById(R.id.recyclerView)
        recyclerView.layoutManager = LinearLayoutManager(context)
        val article = Article(
            "PG_KING",
            "",
            "Android",
            "稀土掘金",
            "稀土掘金是一个技术类内容分享社区，基于互联网技术的优质内容的发现、分享平台，包括iOS、Android、前端、后端、设计等分类下的每日精选内容。主要面对互联网公司的技术开发者、产品经理、运营等人群进行新技术的内容分发。移动端还有收藏、读过等对用户行为的记录，让用户能够更加方便的找到曾经阅读或收藏过的文章。"
        )
        recyclerView.addItemDecoration(
            DividerItemDecoration(
                activity, LinearLayoutManager.HORIZONTAL
            )
        )
        val articles = mutableListOf<Article>()
        articles.add(article)
        articles.add(article)
        articles.add(article)
        articles.add(article)
        articles.add(article)
        articles.add(article)
        articles.add(article)
        articleAdapter = ArticleAdapter(articles)
        recyclerView.adapter = articleAdapter
    }
}